package com.dyz.leetcode._20_dynamicProgramming._121;

public class maxProfit02 {
    // 状态压缩
    public int maxProfit(int[] prices) {
        int profit0 = 0;
        int profit1 = -prices[0];

        for (int i = 1; i < prices.length; i++) {
            profit0 = Math.max(profit0, profit1 + prices[i]);
            profit1 = Math.max(profit1, -prices[i]);
        }

        return profit0;
    }
}
